const path = require('path')
const webpack = require('webpack')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtentsions = ['js', 'css']
const resolve = dir => {
    return path.join(__dirname, dir)
}
module.exports = {
    publicPath: './',
    devServer: {
        host: 'localhost',
        port: 8068,
        proxy: {
            '/jxyzwg': {
                // target: 'http://10.64.81.32:8085', // 代理接口
                target: 'https://www.gneec6.com:18443', // 现网和营运环境
                changeOrigin: true,
                pathRewrite: {
                    '^/jxyzwg': '/jxyzwg' // 代理的路径
                }
            },
            '/jxyz': {
                // target: 'http://192.168.20.20:18080', // 代理接口
                target: 'https://112.51.254.102:18443', // 现网和营运环境
                changeOrigin: true,
                pathRewrite: {
                    '^/jxyz': '/jxyz' // 代理的路径
                }
            },
            '/xvueServer': {
                // target: 'http://100.101.25.238:29009/xvueServer', //代理接口 开发环境
                // target: 'http://10.57.200.89:9010/xvueServer', //代理接口  guowei本地
                target: 'http://smartucpermise-dev.sd.huawei.com/xx/xvueapi', // 代理接口 youming本地
                changeOrigin: true,
                pathRewrite: {
                    '^/xvueServer': '' // 代理的路径
                }
            },
            '/xx/geoserver': {
                target: 'http://smartucpermise-dev.sd.huawei.com/xx/geoserver', // 代理接口 who
                changeOrigin: true,
                pathRewrite: {
                    '^/xx/geoserver': '' // 代理的路径
                }
            },
            '/xx/xsetgisbase': {
                target: 'http://smartucpermise-dev.sd.huawei.com/xx/xsetgisbase/', // 代理接口 who
                changeOrigin: true,
                pathRewrite: {
                    '^/xx/xsetgisbase': '' // 代理的路径
                }
            },
            '/dcp/data/data': {
                target: 'http://smartucpermise-dev.sd.huawei.com/',
                // target:'http://100.101.19.40:21000/data',
                changeOrigin: true,
                pathRewrite: {
                    '^/dcp/data/data': 'dcp/data/data'
                }
            },
            '/auth': {
                target: 'http://smartucpermise-dev.sd.huawei.com/auth', // 代理接口 who
                changeOrigin: true,
                pathRewrite: {
                    '^/auth': '' // 代理的路径
                }
            },
            '/iam/uc': {
                target: 'http://smartucpermise-dev.sd.huawei.com/iam/',
                // target:'http://127.0.0.1:8058',
                changeOrigin: true,
                pathRewrite: {
                    '^/iam/uc': 'uc'
                }
            },
            '/premise_auth/uc': {
                target: 'http://smartucpermise-dev.sd.huawei.com/premise_auth/uc', // 代理接口 who
                changeOrigin: true,
                pathRewrite: {
                    '^/premise_auth/uc': '' // 代理的路径
                }
            },
            '/gridmanager/v1': {
                target: 'http://100.101.19.40:8666/gridmanager/v1',
                changeOrigin: true,
                pathRewrite: {
                    '^/gridmanager/v1': ''
                }
            }
        }
    },
    lintOnSave: false,
    chainWebpack: config => {
        config.resolve.alias
            .set('@', resolve('src'))
            .set('lib', resolve('lib'))
            .set('store', resolve('src/store'))
            .set('util', resolve('src/util'))
        config.module
            .rule('images')
            .use('url-loader')
            .loader('url-loader')
            .tap(options => {
                let op = Object.assign(options, {
                    limit: 1024 * 3,
                    fallback: {
                        loader: 'file-loader',
                        options: {
                            name: 'images/[name].[hash:8].[ext]'
                        }
                    }
                })
                return op
            })
    },
    configureWebpack: {
        devtool: 'source-map',
        plugins: [
            new webpack.ProvidePlugin({
                $: 'jquery',
                jQuery: 'jquery',
                'windows.jQuery': 'jquery'
            }),
            new CompressionWebpackPlugin({
                filename: '[path].gz[query]',
                algorithm: 'gzip',
                test: new RegExp(`\\.(${productionGzipExtentsions.join('|')})$`),
                threshold: 10240,
                deleteOriginalAssets: false,
                minRatio: 0.8
            })
        ],
        externals: {
            // vue: 'Vue',
            // axios: 'axios',
            // vuex: 'vuex',
            // echarts: 'echarts',
            // 'element-ui': 'ELEMENT',
            jquery: '$'
        }
    },
    css: {
        extract: false,
        sourceMap: false
    },
    // 打包时不生成.map文件
    productionSourceMap: false
}
